package com.gewu.pm.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.TestBean;

/**
 * 系统通知列表适配器 暂时没有区分多种类型
 */
public class SystemNotificationAdapter extends AppAdapter<TestBean> {

    private OnDetailsClickListener mDetailsClickListener;

    public SystemNotificationAdapter(Context context) {
        super(context);
    }

    /**
     * 设置"查看详情"点击监听
     */
    public void setOnDetailsClickListener(OnDetailsClickListener listener) {
        mDetailsClickListener = listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mTitleView;
        private final TextView mTimeView;
        private final TextView mContentView;
        private final TextView mViewDetailsView;

        private ItemViewHolder() {
            super(R.layout.system_notification_item);
            mTitleView = findViewById(R.id.tv_title);
            mTimeView = findViewById(R.id.tv_time);
            mContentView = findViewById(R.id.tv_content);
            mViewDetailsView = findViewById(R.id.tv_view_details);

            // 设置"查看详情"点击事件
            mViewDetailsView.setOnClickListener(v -> {
                if (mDetailsClickListener != null) {
                    int position = getViewHolderPosition();
                    TestBean item = getItem(position);
                    mDetailsClickListener.onDetailsClick(position, item);
                }
            });
        }

        @Override
        public void onBindView(int position) {
            TestBean item = getItem(position);
            // 使用 TestBean 的 name 作为标题
            mTitleView.setText(item.getName());
            mTimeView.setText("2025/10/12 16:40");
            mContentView.setText("万家超市加单签到万家超市加单签到万家超市加单签到万家超市加单签到...");
        }
    }

    /**
     * "查看详情"点击监听接口
     */
    public interface OnDetailsClickListener {
        void onDetailsClick(int position, TestBean item);
    }
}

